Fix seemingly same type reports as invalid/incompatible.#5094
Merged
VincentLanglet merged 6 commits intophpstan:2.1.xfrom Mar 1, 2026
Merged
Conversation
…tity - TemplateMixedType and TemplateStrictMixedType with same scope+name represent the same template parameter but fail equals() due to different concrete classes - At level 9+ transformCommonType converts TemplateMixedType to TemplateStrictMixedType in accepting type but not in accepted closure params - Added fallback check in isValidVariance() for invariant templates: if both sides are TemplateType with matching scope and name, treat as equal - New regression test in tests/PHPStan/Rules/Classes/data/bug-13440.php Closes phpstan/phpstan#13440
staabm
reviewed
Feb 28, 2026
|
|
||
| return new CallableType( | ||
| $acceptedType->getParameters(), | ||
| $traverse($this->transformCommonType($acceptedType->getReturnType())), |
Contributor
There was a problem hiding this comment.
Do we need another test for callable?
Contributor
What about throws type? |
Contributor
Author
ClosureType::traverse only touch param and return type. And it kinda make sens here since we're interesting removing null or transforming mixed into strict ; two things which does not make sens for throw type. |
Collaborator
|
This pull request has been marked as ready for review. |
Contributor
|
this seems to also fix phpstan/phpstan#12688 |
staabm
approved these changes
Mar 1, 2026
This was referenced Mar 1, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rework of #5073
Closes phpstan/phpstan#13440
Closes phpstan/phpstan#12688
The issue was that one closure was changed into Closure(template-strict-mixed), while the other stayed Closure(template-mixed) and therefor they were not equal.
Instead of just transforming common in return type, we should transform them in parameter and return types.
Best way to do it it's to transform common type on the closure. (Cf commit 2)
And then when I thought again about it, I think there is some loss on calling transformCommonType inside the
TypeTraverser::mapcall since we might call in multiple times when traversing the types. The first one will transform the mixed to strict mixed, but other call will be useless.So it's seems better to just call it once on the whole accepted type at the end.